package com.steven.ourcontest.collect.view

import android.annotation.SuppressLint
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import com.steven.ourcontest.R
import com.steven.ourcontest.base.BaseActivity
import com.steven.ourcontest.base.BaseFragment
import com.steven.ourcontest.forum.view.ForumFragment
import com.steven.ourcontest.me.view.MeFragment
import kotlinx.android.synthetic.main.activity_collection.*

class CollectionActivity : BaseActivity() {

    private val adapter by lazy {
        AdapterFragmentPager(this)
    }

    override fun getStatusBarColor(): Int {
        return R.color.white
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    override fun getViewId(): Int? {
        return R.layout.activity_collection
    }

    override fun initView() {
        view_pager_content?.adapter = adapter
        view_pager_content?.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                when (position) {
                    0 -> {
                        tv_tab_team?.textSize = 18f
                        tv_tab_match?.textSize = 14f
                    }
                    1 -> {
                        tv_tab_match?.textSize = 18f
                        tv_tab_team?.textSize = 14f
                    }
                }
            }
        })
    }
}

class AdapterFragmentPager(fragmentActivity: FragmentActivity) :
    FragmentStateAdapter(fragmentActivity) {

    private val fragments: ArrayList<BaseFragment> = ArrayList()

    init {
        fragments.add(TeamCollectionFragment())
        fragments.add(MatchCollectionFragment())
    }

    override fun createFragment(position: Int): Fragment {
        return fragments[position]
    }

    override fun getItemCount(): Int {
        return fragments.size
    }
}